using System;
using System.Collections.Generic;
using System.Text;

using NUnit.Framework;
using DataAccessLayer;

namespace Entities

{
    
    [TestFixture]  
    public class TrackFixture:ConnectionFixture
    {
        private static readonly string testTitle = "Test Title";
        private static readonly int testDuration = 33;

        private long insertedId;
        private RecordingDataSet recordingDataSet;

        private TrackGateway gateway;

        [SetUp]
        public void SetUp() {
            gateway = new TrackGateway(Connection);
            recordingDataSet = new RecordingDataSet();
            insertedId = gateway.Insert(testTitle, testDuration, recordingDataSet);
        }
        [TearDown]
        public void TearDown()
        {
            gateway.Delete(insertedId, recordingDataSet);
        }

        [Test]
        public void Retrive() {
            RecordingDataSet.TrackRow row = gateway.FindById(insertedId, recordingDataSet);
            Assert.AreEqual(testTitle, row.title);
            Assert.AreEqual(testDuration, row.duration);
        }

        [Test]
        public void Delete()
        {
            RecordingDataSet emptySet = new RecordingDataSet();
            long deletedId = gateway.Insert("Deleted title", -33, emptySet);

            gateway.Delete(deletedId, emptySet);
            Assert.IsNull(gateway.FindById(deletedId, emptySet));

        }

        [Test]
        public void UpdateTitle()
        {
            string modTitle = "Mod Title";
            
            RecordingDataSet updatedSet = new RecordingDataSet();
            RecordingDataSet.TrackRow modRow = gateway.FindById(insertedId, updatedSet);
            modRow.title = modTitle;

            gateway.Update(updatedSet);

            Assert.AreEqual(modTitle, gateway.FindById(insertedId, new RecordingDataSet()).title);
         
        }

        [Test]
        public void UpdateDuration()
        {
            int modDuration = 777;

                        RecordingDataSet updatedSet = new RecordingDataSet();
            RecordingDataSet.TrackRow modRow = gateway.FindById(insertedId, updatedSet);
            modRow.duration = modDuration;

            gateway.Update(updatedSet);

            Assert.AreEqual(modDuration, gateway.FindById(insertedId, new RecordingDataSet()).duration);

        }


    }
}
